package com.example.springaopdemo.aspect;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@Aspect
public class CostTimeAspect {
    @SneakyThrows//自动生成try catch
    @Around("@annotation(com.example.springaopdemo.aspect.CostTime)")//表示所有加了CostTime注解的都在范围内,这也是一个切点
    public Object costtime(ProceedingJoinPoint joinPoint){
        long start = System.currentTimeMillis();
        Object object = joinPoint.proceed();
        log.info(joinPoint.getSignature().toShortString()+"耗时:"+(System.currentTimeMillis()-start));
        return object;
    }
}
